<%@ page language="java"
         contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ page isELIgnored="false" %><!-- isELIgnored=true禁用EL表达式 -->

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!-- JSTL格式化标签 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<html>
<head>
    <meta charset="UTF-8">
    <title>我的订单</title>
    <script src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/index.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/indexstyle.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
</head>
<body>

<div class="site-nav-bg">
    <div class="site-nav w1200">
        <p class="sn-back-home">
            <i class="layui-icon layui-icon-home"></i>
            <a href="${pageContext.request.contextPath}/shop/shopPage">首页</a>
        </p>
        <div class="sn-quick-menu">
            <div class="sp-cart"><i class="layui-icon layui-icon-form"></i><a style="margin-left: 5px"
                                                                              href="${pageContext.request.contextPath}/shop/goods/orderPage">我的订单</a></div>
            <div class="sp-cart" style="margin-left: 15px"><i class="layui-icon layui-icon-cart-simple"></i><a
                    style="margin-left: 5px" ><span style="color: red">购物车</span></a></div>
            <c:if test="${sessionScope.u.id != null}">
                <div style="margin-left: 10px">
                    <a href="${pageContext.request.contextPath}/user/userPage">
                        <div><i class="layui-icon layui-icon-user"></i>&nbsp;&nbsp;欢迎用户:<span>${sessionScope.u.uName}</span></div>
                    </a>
                </div>
            </c:if>
            <c:if test="${sessionScope.u.id == null}">
                <div>
                    <div class="login" style="margin-left: 15px"><i class="layui-icon layui-icon-user"></i><a
                            style="margin-left: 5px" href="${pageContext.request.contextPath}/mall/login">登录</a></div>
                </div>
            </c:if>
        </div>
    </div>
</div>

<div class="content content-nav-base shopcart-content">
    <div class="main-nav">
        <div class="inner-cont0">
            <div class="inner-cont1 w1200">
                <div class="inner-cont2">
                    <form class="layui-form" action="${pageContext.request.contextPath}/car/carPage" method="post">
                        <div class="layui-input-inline">
                            <a class="active">购物车查询</a>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="gName"  id="categoryName" value="${gName}" class="layui-input" placeholder="请输入商品名称">
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn layui-btn-sm layui-btn-primary" type="submit">
                                <i class="layui-icon layui-icon-search"></i>
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="cart w1200">
        <div class="cart-table-th">
            <div class="th th-chk">
              <div class="select-all">&nbsp;&nbsp;&nbsp;&nbsp;

               </div>
            </div>
            <div class="th th-item">
                <div class="th-inner">商品</div>
            </div>
            <div class="th th-price">
                <div class="th-inner">单价</div>
            </div>
            <div class="th th-amount">
                <div class="th-inner">数量</div>
            </div>
            <div class="th th-sum">
                <div class="th-inner">总额</div>
            </div>
            <div class="th th-op">
                <div class="th-inner">操作</div>
            </div>
        </div>
        <div class="OrderList">
            <div class="order-content" id="list-cont" style="background-color: #fff5ff">
                <c:if test="${list.size() == 0}">
                    <h1>购物车内没有查询的订单</h1>
                </c:if>
                <c:if test="${list.size() != 0}">
                    <c:forEach items="${list}" var="car">
                        <tr>
                            <ul class="item-content layui-clear">
                                <li class="th th-chk">

                                </li>
                                <li class="th th-item">
                                    <div class="item-cont">
                                        <a><img src="${car.imgUrl}" alt=""></a>
                                        <div class="text">
                                            <div class="title layui-font-20" id="goodsName" >${car.gName}</div>
                                        </div>
                                    </div>
                                </li>
                                <li class="th th-price">
                                    <span class="th-su" style="font-size: 16px" id="sellingPrice">￥${car.gPrice}</span>
                                </li>
                                <li class="th th-amount">
                                    <div class="box-btn layui-clear" style="margin-left: -40px">
<%--                                            <span id="count" >${car.buyCount}</span>--%>
<%--                                        <button onclick="addcount()" class="layui-icon layui-icon-up"></button>--%>
                                        <span class="amount">${car.buyCount}</span>
<%--                                        <button onclick="subcount()" class="layui-icon layui-icon-down"></button>--%>
<%--                                            <input id="goodsCount" class="Quantity-input" value="${car.buyCount}"--%>
<%--                                                   disabled="disabled">--%>
                                    </div>
                                </li>
                                <li class="th th-sum">
                                    <span class="sum" style="font-size: 18px">￥${car.buyCount * car.gPrice} RMB</span>
                                </li>
                                <li class="th th-op">
                                    <span class="dele-btn" onclick="del(${car.id})">删除</span>
                                    <button class="layui-btn" style="background-color: #ea7e0f" onclick="buygoods(${car.id},${car.gId},${car.buyCount})">购买</button>
                                </li>
                            </ul>
                        </tr>
                    </c:forEach>
<%--                    <div id="test1"></div>--%>
                </c:if>
            </div>

        </div>
    </div>
</div>

<script type="text/javascript">
    layui.use('laypage', function(){
        var laypage = layui.laypage;

        //执行一个laypage实例
        laypage.render({
            elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
            ,count: 50 ,//数据总数，从服务端得到
            limit: 3
        });
    });
    function changeGoods(categoryName,money,counts,userId,img,no) {
        layer.open({
            type: 2,
            title: "付款",
            area: ['900px', '650px'],
            offset: '100px',
            content: "http://localhost:8080/SSM/cart/pay?categoryName=" + categoryName+"&money="+money+"&counts="+counts+
                "&userId="+userId +"&img="+img+"&no="+no,
            cancel: function(index, layero){
                if(confirm('订单已经生成 请在个人订单支付')){ //只有当点击confirm框的确定时，该层才会关闭
                    layer.close(index)
                    window.parent.location.reload();
                }
                return false;
            }
        });
    }

    function buygoods(id,gId,buyCount){
        var params ="carId="+id+"&buyCount="+buyCount+"&gId="+gId;
        console.info(params);
        window.location.href = "${pageContext.request.contextPath}/shop/goods/payPage?"+params;
    }

    function del(id){
        $.ajax({
            url:"${pageContext.request.contextPath}/car/deleteOneGoodsInCar",
            data: "id="+id,
            type:"post",
            success:function (code){
                if (code == "1") {
                    alert("删除成功");
                } else {
                    alert("删除失败");
                }
                window.location.reload();
            }
        })
    }


</script>
</body>
</html>
